﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data;
using UniMana.Utils.Data;
using UniMana.Data;

namespace UniMana.Data
{
    public static class ReportSubjectOpenedOfClassData_Chi
    {
        public static IQueryable GetSubjectOfClassData(this Table<Training_Class> traCls, Table<Catalogue_SchoolYear> cataSch, Table<Catalogue_Term> term,
                                                            Table<Training_Subject_Class> traSubCls, Table<Training_Subject> traSub, int _iCou, int _iMaj,int _iTraClass)
        {
            var view = from t in traSubCls
                       join t0 in cataSch on new { Catalogue_SchoolYearKey = Convert.ToInt32(t.Catalogue_SchoolYearKey) } equals new { Catalogue_SchoolYearKey = t0.Catalogue_SchoolYearKey }
                       join t1 in traSub on new { Training_SubjectKey = Convert.ToInt32(t.Training_SubjectKey) } equals new { Training_SubjectKey = t1.Training_SubjectKey }
                       join t2 in traCls on new { Training_ClassKey = Convert.ToInt32(t.Training_ClassKey) } equals new { Training_ClassKey = t2.Training_ClassKey }
                       join t3 in term on new { Catalogue_TermKey = Convert.ToInt32(t.Catalogue_TermKey) } equals new { Catalogue_TermKey = t3.Catalogue_TermKey }
                       where
                          t.Training_ClassKey==_iTraClass 
                     
                       select new
                       {
                           Catalogue_SchoolYearKey = (System.Int32?)t0.Catalogue_SchoolYearKey,
                           SchoolYearName = t0.Name,
                           t.Training_Subject_ClassKey,
                           t.ID,
                           Expr6 = t.Name,
                           Training_SubjectKey = (System.Int32?)t1.Training_SubjectKey,
                           MaMH = t1.ID,
                           TenMH = t1.Name,
                           TongSoTC=t1.TotalCredits,
                           t.Opened,
                           Catalogue_TermKey = (System.Int32?)t3.Catalogue_TermKey,
                           TermName=t3.Name,
                           Training_ClassKey = (System.Int32?)t2.Training_ClassKey,
                           TenLopDV = t2.Name
                       }; return view;

        }
        /// <summary>
        /// Lấy lớp theo khóa, ngành
        /// </summary>
        /// <param name="traCls"></param>
        /// <param name="cataCou"></param>
        /// <param name="cataMaj"></param>
        /// <param name="_iCou"></param>
        /// <param name="_iMaj"></param>
        /// <returns></returns>
        public static IQueryable GetClassData(this Table<UniMana.Data.Training_Class> traCls, int _iCouserKey,int _iDepartmentKey,int _iMajorKey)
        {
            var view2 = from _class in traCls
                        where _class.Catalogue_CourseKey == _iCouserKey
                        where _class.Catalogue_MajorKey == _iMajorKey
                        where _class.Catalogue_DepartmentKey == _iDepartmentKey
                        select _class;
            return view2;
        }
        /// <summary>
        /// Lấy mã khoa với mã ngành
        /// </summary>
        /// <param name="nCatalogue_Major"></param>
        /// <param name="m_iMajorKey"></param>
        /// <returns></returns>

        //public static int GetDepartmentWithMajor(this Table<Catalogue_Major> nCatalogue_Major, int m_iMajorKey)
        //{
        //    var values = from t in nCatalogue_Major
        //                 where t.Catalogue_MajorKey == m_iMajorKey
        //                 select t;
        //    if (values.Count() > 0)
        //        return int.Parse(values.FirstOrDefault().Catalogue_DepartmentKey.ToString());
        //    else
        //        return 0;
        //}
    }
}
